import 'package:mobile_app.core/core/domain/entities/learning_content/lexical_item/lexical_item.dart';
import 'package:mobile_app.home.core/core/domain/entities/card_actions/mark_as_known_card_action.dart';
import 'package:mobile_app.home.core/core/domain/helpers/is_mark_as_known_card_action_permitted/helper.dart';
import 'package:mobile_app.home.core/core/domain/helpers/is_mark_as_known_card_action_reasonable/helper.dart';

abstract class CreateMarkAsKnownCardActionIfReasonable {
  MarkAsKnownCardAction? call({
    required LexicalItem lexicalItem,
    required bool lexicalItemPermitted,
  });
}

class CreateMarkAsKnownCardActionIfReasonableImpl
    implements CreateMarkAsKnownCardActionIfReasonable {
  const CreateMarkAsKnownCardActionIfReasonableImpl({
    required IsMarkAsKnownCardActionPermitted isMarkAsKnownCardActionPermitted,
    required IsMarkAsKnownCardActionReasonable isMarkAsKnownCardActionReasonable,
  })  : _isMarkAsKnownCardActionPermitted = isMarkAsKnownCardActionPermitted,
        _isMarkAsKnownCardActionReasonable = isMarkAsKnownCardActionReasonable;

  final IsMarkAsKnownCardActionPermitted _isMarkAsKnownCardActionPermitted;
  final IsMarkAsKnownCardActionReasonable _isMarkAsKnownCardActionReasonable;

  @override
  MarkAsKnownCardAction? call({
    required LexicalItem lexicalItem,
    required bool lexicalItemPermitted,
  }) {
    final cardActionReasonable = _isMarkAsKnownCardActionReasonable(
      lexicalItem: lexicalItem,
    );

    if (!cardActionReasonable) {
      return null;
    }

    final cardActionPermitted = _isMarkAsKnownCardActionPermitted(
      lexicalItemPermitted: lexicalItemPermitted,
    );

    final cardAction = MarkAsKnownCardAction(
      permitted: cardActionPermitted,
    );

    return cardAction;
  }
}
